Skip to content

BaseRuleSyntaxHighlighter

Sub classes

Name Children Inherits
MarkdownHighlighter
prettyqt.syntaxhighlighters.markdownhighlighter
    PythonHighlighter
    prettyqt.syntaxhighlighters.pythonhighlighter
    Syntax highlighter for the Python language.
      YamlHighlighter
      prettyqt.syntaxhighlighters.yamlhighlighter

        Base classes

        Name Children Inherits
        SyntaxHighlighter
        prettyqt.gui.syntaxhighlighter

        ⋔ Inheritance diagram

        graph TD
          1806335888["syntaxhighlighters.BaseRuleSyntaxHighlighter"]
          1397204487["gui.SyntaxHighlighter"]
          1524332846["gui.SyntaxHighlighterMixin"]
          3227531497["core.ObjectMixin"]
          2751680898["builtins.object"]
          1270797816["QtGui.QSyntaxHighlighter"]
          3984060476["QtCore.QObject"]
          37984305["Shiboken.Object"]
          1397204487 --> 1806335888
          1524332846 --> 1397204487
          3227531497 --> 1524332846
          2751680898 --> 3227531497
          2751680898 --> 1524332846
          1270797816 --> 1397204487
          3984060476 --> 1270797816
          37984305 --> 3984060476
          2751680898 --> 37984305

        🛈 DocStrings

        Bases: SyntaxHighlighter

        Source code in prettyqt/syntaxhighlighters/baserulesyntaxhighlighter.py
        class BaseRuleSyntaxHighlighter(gui.SyntaxHighlighter):
            RULES: ClassVar[list] = []
        
            @classmethod
            def iter_rules(cls) -> Iterator[tuple[Pattern, int, gui.TextCharFormat]]:
                for rule in cls.RULES:
                    if isinstance(rule.compiled, list):
                        for i in rule.compiled:
                            yield (i, rule.nth, rule.fmt)
                    else:
                        yield (rule.compiled, rule.nth, rule.fmt)
        
            def highlightBlock(self, text: str):
                """Apply syntax highlighting to the given block of text."""
                # Do other syntax formatting
                for expression, nth, fmt in self.iter_rules():
                    for match in expression.finditer(text):
                        span = match.span(nth)
                        self.setFormat(span[0], span[1] - span[0], fmt)
        

        highlightBlock(text: str)

        Apply syntax highlighting to the given block of text.

        Source code in prettyqt/syntaxhighlighters/baserulesyntaxhighlighter.py
        def highlightBlock(self, text: str):
            """Apply syntax highlighting to the given block of text."""
            # Do other syntax formatting
            for expression, nth, fmt in self.iter_rules():
                for match in expression.finditer(text):
                    span = match.span(nth)
                    self.setFormat(span[0], span[1] - span[0], fmt)
        

        :fa-brands-github: Show source on GitHub